package com.dao.provider;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

/**
 * @author cj
 * @date 2019/10/14
 */
public class EmployeeDaoProvider {

    public String getEmpById() {
        return "select id,username from employee where id =#{id}";
    }

    //要么不添加参数
    public String getEmpById2() {
        return "select id,username from employee where id =#{id} and gender = #{gender}";
    }
    // 要么添加参数,并且也加上@Param注解
  /*  public String getEmpById2(@Param("id") int id, @Param("gender")int gender){

        return "select id,username from employee where id =#{id} and gender = #{gender}";
    }*/


    /**
     * 加上@Param注解表明gender这个参数的值,取自dao方法的哪个参数的值
     *
     * @param gender
     * @return
     */
    public String getEmpById3(@Param("gender") int gender) {
        System.out.println("-----debug: gender = " + gender);
        if (gender < 0) {
            return "select id,username from employee where id =#{id} ";
        }
        return "select id,username from employee where id =#{id} and gender = #{gender}";
    }


    public String getEmpById4() {
        return new SQL() {
            {
                SELECT("id,username");
                FROM("employee");
                WHERE("id=#{id}");
                AND();
                WHERE("gender=#{gender}");
            }
        }.toString();
    }
}
